package com.pro.schedule.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.pro.schedule.entity.Target;
import com.pro.schedule.service.TargetService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
public class TargetController {
    @Resource
    TargetService targetService;

    @ApiOperation("获取目标")
    @PostMapping("/schedule/target/getList")
    public IPage<Target> getTargetIPage(@RequestBody Target target, HttpServletRequest request) {
        String token = request.getHeader("Authorization");
        return targetService.getTargetIPage(token, target.getPage());
    }

    @ApiOperation("保存或修改目标")
    @PostMapping("/schedule/target/saveOrUpdate")
    public String saveOrUpdateTarget(@RequestBody Target target, HttpServletRequest request) throws Exception {
        String token = request.getHeader("Authorization");
        return targetService.saveOrUpdateTarget(token, target);
    }

    @ApiOperation("删除指定目标")
    @PostMapping("/schedule/target/delete")
    public String deleteTarget(@RequestBody Target target) throws Exception {
        return targetService.deleteTarget(target.getTargetId());
    }

    @ApiOperation("修改目标状态")
    @PostMapping("/schedule/target/changeStatus")
    public String changeTargetStatus(@RequestBody Target target) throws Exception {
        return targetService.changeTargetStatus(target.getTargetId());
    }
    @ApiOperation("获取目标数量")
    @PostMapping("/schedule/target/getCount")
    public int getTargetCount(HttpServletRequest request){
        String token = request.getHeader("Authorization");
        return targetService.getTargetCount(token);
    }
}
